package com.cskaoyan.controller.stage;

import com.cskaoyan.model.Footprint;
import com.cskaoyan.model.bo.BaseParamBO;
import com.cskaoyan.model.vo.*;
import com.cskaoyan.service.FootprintService;
import com.cskaoyan.service.UserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName: WxFootprintController
 * @Description: TODO 微信用户足迹模块
 * @Author:zhoukang
 * @Date: 2022/5/7 22:28
 * @Version: 1.0
 **/
@RestController
@RequestMapping("wx/footprint")
public class WxFootprintController {
    @Autowired
    FootprintService footprintService;

    @Autowired
    UserService userService;
    /**
     * @author: zhoukang
     * @description: TODO 查询用户足迹
     * @date: 2022/5/8 16:01
     */
    @GetMapping("list")
    public BaseRespVO<DataVO<WxFootPrintVO>> list(BaseParamBO paramBO){
        //shiro获取用户信息
        Subject subject = SecurityUtils.getSubject();
        String username = (String) subject.getPrincipals().getPrimaryPrincipal();
        //根据用户信息取得用户的id
        Integer userId = userService.getUserIdByUsername(username);
        DataVO<WxFootPrintVO> dataVO =footprintService.queryUserFootprint(userId,paramBO);
        return BaseRespVO.ok(dataVO);
    }

    /**
     * @author: zhoukang
     * @description: TODO 逻辑删除用户足迹
     * @date: 2022/5/8 16:09
     */
    @PostMapping("delete")
    public ExceptionVO delete(@RequestBody Footprint footprint){
        //逻辑删除
        footprint.setDeleted(true);

        footprintService.deleteFootprint(footprint);
        return new ExceptionVO();
    }


}
